<div class="content-titulo">
    <div class="filtro">
        <form id="form_filtro" method="get" action="">
            <i>Filtrar</i>
            <?php 
                //$f_cur = new Sistema_Model_DbTable_Catsegmento();
                //$f_cur = $f_cur->fetchAll('CTS_STA = 1');
                $f_cur = $this->db->fetchAll('SELECT SQL_CACHE CTS_ID,CTS_NOM FROM CATSEGMENTO WHERE CTS_STA = 1 ORDER BY CTS_ORD ASC');
            
                $html = '<select id="filtroseg" name="filtroseg">';
                $html .= '<option value="">Todos Segmentos</option>';
                foreach($f_cur as $r){   
                    $select = $this->filtroseg == $r['CTS_ID'] ? 'selected':''; 
                    $html .= '<option '.$select.' value="'.$r['CTS_ID'].'">'.$r['CTS_NOM'].'</option>'; 
                }
                echo $html .= '</select>';
            ?>
            &nbsp;
            <?php 
                          
                $html = '<select id="filtrocat" name="filtrocat">';
                $html .= '<option value="">Todas Categorias</option>';
                
                if($this->filtroseg > 0){
                    
                    //$f_cur = new Sistema_Model_DbTable_Categoria();
                    //$f_cur = $f_cur->fetchAll('CTS_ID='.$this->filtroseg.' and CAT_STA = 1');
                    $where = '';
                    if($this->filtroseg > 0) $where = 'CTS_ID = '.$this->filtroseg.' AND';
                    $f_cur = $this->db->fetchAll('SELECT SQL_CACHE CAT_ID,CAT_NOM FROM CATEGORIA WHERE '.$where.' CAT_STA = 1 ORDER BY CAT_NOM ASC');
            
                    foreach($f_cur as $r){   
                        $select = $this->filtrocat == $r['CAT_ID'] ? 'selected':''; 
                        $html .= '<option '.$select.' value="'.$r['CAT_ID'].'">'.$r['CAT_NOM'].'</option>'; 
                    }
                }
                echo $html .= '</select>';
            ?>
            &nbsp;
            <input type="text" name="dscfiltro" value="<?php echo $this->dscfiltro; ?>" placeholder="Produto" />
            
            
            <input type="submit" class="btn-pdr" name="buscar" value="buscar" />
        </form>
    </div>
    
    <div class="content-btn">
        <a href="<?php echo $this->url(array('controller' => $this->controller, 'action' => 'edit')); ?>">+</a>
    </div>
    
    <h2><?php echo $this->titulo;?></h2>
</div>
    
    
<div class="content-list">
    
<?php foreach ($this->result as $row) { 
    $cts = $this->db->fetchRow('SELECT SQL_CACHE * FROM CATSEGMENTO WHERE CTS_ID = '.$row['CTS_ID']);
    $cat = $this->db->fetchRow('SELECT SQL_CACHE * FROM CATEGORIA WHERE CAT_ID = '.$row['CAT_ID']);
    $gra = $this->db->fetchRow('SELECT SQL_CACHE * FROM GRADETAMANHOS WHERE GRA_ID = '.$row['GRA_ID']);
    $for = $this->db->fetchRow('SELECT SQL_CACHE * FROM FORNECEDOR WHERE FOR_ID = '.$row['FOR_ID']);
    $mat = $this->db->fetchRow('SELECT SQL_CACHE * FROM MATERIAL WHERE MAT_ID = '.$row['MAT_ID']);
    $cor = $this->db->fetchRow('SELECT SQL_CACHE * FROM GRADECOR WHERE GRC_ID = '.$row['GRC_ID']);
    $corpri = array();

?>
    <div class="item" style="height:122px">    
        <div class="col" style="width: 120px;padding: 10px 20px;">
        <?php $imgs_pri = glob('public/upload/produto/'.$row['PRO_ID'].'_*_hcp.*');
        if(isset($imgs_pri[0])){
        ?> 
            <img src="<?php echo $this->urlbase.'/'.$imgs_pri[0]; ?>" />
        <?php } ?>
        </div>
        <div class="col" style="width: 200px">
            <p><strong>Cód. Pro: <?php echo $row['PRO_ID']; ?></strong></p>
            <p><strong>Seg: </strong><?php echo $cts['CTS_NOM']; ?></p>
            <p><strong>Cat: </strong><?php if($row['CAT_ID'] > 0) echo $cat['CAT_NOM']; else echo 'Todos'; ?></p>
            <p><strong>Destaque: </strong><?php echo tools::returnStaSN($row['PRO_STAPRO']); ?></p>
            <p><strong>Status: </strong><?php echo tools::returnStatus($row['PRO_STA']); ?></p>            
        </div>
        <div class="col" style="width: 200px">
            <p><strong>Título: </strong><?php echo $row['PRO_NOM']; ?></p>
            <p><strong>For: </strong><?php echo $for['FOR_NOM']; ?></p>
            <p><strong>Mat: </strong><?php echo $mat['MAT_NOM']; ?></p>
            <p><strong>Tam: </strong><?php if(isset($gra->GRA_ID)) echo $gra['GRA_NOM']; ?></p>
            <p><strong>Cor: </strong><?php if(isset($cor->GRC_ID)) echo $cor['GRC_NOM']; ?></p>
        </div>
        
        <div class="col" style="width: 200px">
            <p><strong>Qtd: </strong><?php echo $row['PRO_QTDMIN']; ?> peças</p>
            <p><strong>Promoção: </strong><?php echo tools::float_to_money($row['PRO_VALPRO']); ?></p>
            <p><strong>Data Valide: </strong><?php echo Datetools::amd_dma($row['PRO_DATPRO']) ?></p>
            <p><strong>Valor: </strong>R$<?php echo tools::float_to_money($row['PRO_VAL']); ?> unidade</p>
            <p><strong>Prazo: </strong> <?php echo $row['PRO_PZO']; ?> dias</p>
        </div>
        
       
        
        <div class="btn-actions" style="padding-top: 10px;">
            <?php if($this->per_edt){?><a class="btn-pdr" href="<?php echo $this->url(array('controller' => $this->controller, 'action' => 'edit', 'id' => $row['PRO_ID'])); ?>">Editar</a><?php }?>
            <?php if($row['PRO_STA'] == 0){ ?><a class="btn-pdr" href="<?php echo $this->url(array('controller' => $this->controller, 'action' => 'delete', 'id' => $row['PRO_ID'])); ?>">Deletar</a><?php } ?>
        </div>

      </div>
    <?php } ?>
</div>
<?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?>